<?php

namespace App\Models;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @SWG\Definition(
 *      definition="Channel",
 *      required={"name", "country", "state_id", "state", "state_name", "county_id", "county", "county_name", "zip_id", "zip_code", "zip", "zip_name", "address", "linkman_name", "linkman_phone", "linkman_wechat", "linkman_duty"},
 *      @SWG\Property(
 *          property="id",
 *          description="id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="name",
 *          description="name",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="state_id",
 *          description="state_id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="state",
 *          description="state",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="state_name",
 *          description="state_name",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="county_id",
 *          description="county_id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="county",
 *          description="county",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="county_name",
 *          description="county_name",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="zip_id",
 *          description="zip_id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="zip_code",
 *          description="zip_code",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="zip",
 *          description="zip",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="zip_name",
 *          description="zip_name",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="address",
 *          description="address",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="linkman_name",
 *          description="linkman_name",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="linkman_phone",
 *          description="linkman_phone",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="linkman_wechat",
 *          description="linkman_wechat",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="linkman_duty",
 *          description="linkman_duty",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="status",
 *          description="status",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="updated_at",
 *          description="updated_at",
 *          type="string",
 *          format="date-time"
 *      ),
 *      @SWG\Property(
 *          property="created_at",
 *          description="created_at",
 *          type="string",
 *          format="date-time"
 *      )
 * )
 */
class Channel extends Model
{
    use SoftDeletes;

    public $table = 'channels';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'name',
        'short_name',
        'logo',
        'phone',
        'email',
        'regtime',
        'type',
        'introduction',
        'official_account',
        'official_account_qrcode',
        'web_url',
        'country',
        'state_id',
        'state',
        'state_name',
        'county_id',
        'county',
        'county_name',
        'zip_id',
        'zip_code',
        'zip',
        'zip_name',
        'province',
        'city',
        'address',
        'linkman_name',
        'linkman_phone',
        'linkman_wechat',
        'linkman_duty'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'name' => 'string',
        'short_name' => 'string',
        'logo' => 'string',
        'phone' => 'string',
        'email' => 'string',
        'regtime' => 'date',
        'type' => 'integer',
        'introduction' => 'string',
        'official_account' => 'string',
        'official_account_qrcode' => 'string',
        'web_url' => 'string',
        'state_id' => 'integer',
        'state' => 'string',
        'state_name' => 'string',
        'county_id' => 'integer',
        'county' => 'string',
        'county_name' => 'string',
        'zip_id' => 'integer',
        'zip_code' => 'string',
        'zip' => 'string',
        'zip_name' => 'string',
        'province' => 'string',
        'city' => 'string',
        'address' => 'string',
        'linkman_name' => 'string',
        'linkman_phone' => 'string',
        'linkman_wechat' => 'string',
        'linkman_duty' => 'string',
        'status' => 'integer'
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'name' => 'required|between:2,50',
        // 'logo' => 'required',
        'phone' => 'required',
        'email' => 'email',
        // 'regtime' => 'required|date',
        // 'introduction' => 'required',
        // 'official_account' => 'required',
        // 'official_account_qrcode' => 'required',
        // 'web_url' => 'required|url',
        'province' => 'required',
        'city' => 'required',
        // 'address' => 'required',
        // 'linkman_name' => 'required|between:1,20',
        // 'linkman_phone' => 'required',
        // 'linkman_wechat' => 'required',
        // 'linkman_duty' => 'required|between:1,30',
    ];

    public function getRegtimeAttribute($value)
    {
        return $value;
    }
}